<template>
  <div class="mod-api__user">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-input v-model.trim="state.dataForm.realName" placeholder="真实姓名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="state.dataForm.companyId" placeholder="请选择入职企业" value-key="" clearable filterable @change="">
          <el-option key="" label="全部" value=""> </el-option>
          <el-option v-for="item in vcxvfgt" :key="item.id" :label="item.name" :value="item.id"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="state.getDataList()">搜索</el-button>
      </el-form-item>
      <!-- <el-form-item>
        <el-button  type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item> -->
      <el-form-item>
        <el-button type="danger" @click="state.deleteHandle()">删除</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="state.exportHandle()">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <!-- <el-table-column prop="name" label="昵称" header-align="center" align="center"></el-table-column> -->

      <el-table-column prop="realName" label="姓名" header-align="center" align="center"></el-table-column>
      <el-table-column label="性别" width="60" header-align="center" align="center">
        <template #default="scope">
          <span v-if="scope.row.gender === 0">男</span>
          <span v-if="scope.row.gender === 1">女</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="gender" width="60" label="性别 " header-align="center" align="center">
        <template #default="scope">
            {{ xingbie(scope.row.gender ) }}
          </template>
      </el-table-column> -->
      <!-- <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column> -->
      <el-table-column prop="idCard" width="200" label="身份证" header-align="center" align="center"></el-table-column>
      <el-table-column prop="companyId" label="驻场企业" width="200" header-align="center" align="center">
        <template #default="scope">
          {{ jkxdfxsd(scope.row.companyId) }}
        </template>
      </el-table-column>

      <el-table-column prop="companyNo" label="员工工号" header-align="center" align="center"></el-table-column>
      <!-- <el-table-column prop="username" label="用户名 微信号" header-align="center" align="center"></el-table-column> -->
      <el-table-column prop="mobile" label="手机号" width="140" header-align="center" align="center"></el-table-column>
      <el-table-column prop="balance" label="余额" header-align="center" align="center"></el-table-column>
      <!-- <el-table-column prop="password" label="密码" header-align="center" align="center"></el-table-column> -->
      <!-- <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column> -->

      <!-- <el-table-column prop="headUrl" label="头像" header-align="center" align="center"></el-table-column> -->

      <!-- <el-table-column prop="email" label="邮箱" header-align="center" align="center"></el-table-column> -->

      <!-- <el-table-column prop="idAddress" label="籍贯地址" header-align="center" align="center"></el-table-column> -->
      <!-- <el-table-column prop="isAuthentication" label="是否实名" header-align="center" align="center"></el-table-column> -->

      <el-table-column prop="createTime" label="注册时间" header-align="center" align="center" width="160"></el-table-column>

      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="200">
        <template v-slot="scope">
          <el-button type="primary" link @click="state.deleteHandle(scope.row.id)">删除</el-button>
          <el-button type="primary" link @click="zhuchangser(scope.row, true)" v-if="!scope.row.isStaff">设为驻场员</el-button>
          <el-button type="primary" link @click="zhuchangser(scope.row, false)" v-else>取消驻场员</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList">确定</add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { reactive, ref, toRefs } from "vue";
import AddOrUpdate from "./siteAgent-add-or-update.vue";
import { xingbie } from "@/utils/utils";
import { dxget, zkjsd, transferTimeYMD, dxpost } from "@/utils/utils";
import { ElMessage } from "element-plus";
const vcxvfgt = ref([]);
const view = reactive({
  deleteIsBatch: true,
  getDataListURL: "/sys/apiUser/page?isStaff=true",
  getDataListIsPage: true,
  exportURL: "/sys/apiUser/export?isStaff=true",
  deleteURL: "/api/user"
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.init(id);
};
const injxsd = async () => {
  const resd = await dxget("/sys/tmcompany/option");
  vcxvfgt.value = resd;
};
injxsd();
const jkxdfxsd = (item) => {
  try {
    return vcxvfgt.value.filter((a) => a.id == item)[0].name;
  } catch (e) {
    return "-";
  }
};

const zhuchangser = async (data, isStaff) => {
  await dxpost(
    "/api/user",
    {
      id: data.id,
      isStaff
    },
    "put"
  );
  data.isStaff = isStaff;
  ElMessage({
    message: "操作成功",
    type: "success"
  });
};
const xcxzety = async (data, dj) => {
  await dxpost(
    "/api/user",
    {
      id: data.id,
      brokerLevel: dj,
      isBroker: true
    },
    "put"
  );
  data.brokerLevel = dj;
};
const fdsfsdrtt = (data) => {
  let kmxcet = "";
  if (data == 0) {
    kmxcet = "设置经纪人";
  }
  if (data == 1) {
    kmxcet = "中级经纪人";
  }
  if (data == 2) {
    kmxcet = "高级经纪人";
  }
  if (data === "") {
    kmxcet = "设置经纪人";
  }
  return kmxcet;
};
</script>
